package com.zhongwang.mms.module.buy.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.BShoppingPlanChange;
import com.zhongwang.mms.module.buy.model.ShoppingPlanModel;
import com.zhongwang.mms.module.buy.service.BuyPlanCheckService;
import com.zhongwang.mms.module.buy.service.ExportBuyPlanService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description: 采购计划审阅
 * 查看 -> buy:buycheck:view
 * 驳回,审阅 -> buy:buycheck:edit
 *
 * @Author: China.sgl
 * @Date: 2020/4/7 14:42
 */
@SuppressWarnings("ALL")
@Controller
@RequestMapping("/buy/buyPlanCheck")
public class BuyPlanCheckController extends BaseController {

    @Autowired
    private BuyPlanCheckService service;

    /**
     * 采购计划审阅页面
     *
     * @return 路径
     */
    @GetMapping("{title}")
    @RequiresPermissions({"buy:buycheck:view"})
    public String check(Model model, @PathVariable("title") String title) {
        model.addAttribute("stocks", service.findStocks());
        model.addAttribute("title", title);
        return "buy/buyPlanCheck/page";
    }

    /**
     * 列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    public JsonResult list(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findBuyPlanByQuery(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 审批采购计划
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/commit")
    @RequiresPermissions({"buy:buycheck:edit"})
    public JsonResult commit(Integer id) {
        return jsonResult(service.commitById(id));
    }

    /**
     * 批量已阅采购计划
     *
     * @param ids 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/commitAll")
    @RequiresPermissions({"buy:buycheck:edit"})
    public JsonResult commit(Integer[] ids) {
        return jsonResult(service.commitInId(ids));
    }
    /**
     * 批量未阅采购计划
     *
     * @param ids 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancelAll")
    @RequiresPermissions({"buy:buycheck:edit"})
    public JsonResult cancelAll(Integer[] ids) {
        return jsonResult(service.cancelInId(ids));
    }

    /**
     * 未阅采购计划
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancel")
    @RequiresPermissions({"buy:buycheck:edit"})
    public JsonResult cancel(Integer id) {
        return jsonResult(service.cancel(id));
    }

}
